<template>
    <div style="height:100%;width:100%;position:relative;" ref="maindev">
        <div class="pagetop">
            <!-- height 32px 13 67%-->
            <table style="width: 100%; font-size: 12px;" border="0">
                <col style="width: 4%;" />
                <col style="width: 7%;" />
                <col style="width: 1%;" />
                <col style="width: 7%;" />
                <col style="width: 4%;" />
                <col style="width: 10%;" />
                <col style="width: 4%;" />
                <col style="width: 11%;" />
                <col style="width: 4%;" />
                <col style="width: 10%;" />
                <col style="width: 4%;" />
                <col style="width: 10%;" />
                <col style="width: 33%;" />
                <tr>
                    <td>标本日期</td>
                    <td>
                        <el-date-picker v-model="sample_startdt" :able="false" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" style="width: 100%;min-width: 100px;" :picker-options="pickerOptions" :clearable="false" :key="startkey">
                        </el-date-picker>
                    </td>
                    <td align="center">至</td>
                    <td>
                        <el-date-picker v-model="sample_enddt" type="date" :able="false" placeholder="选择日期" value-format="yyyy-MM-dd" style="width: 100%;min-width: 100px;" :picker-options="pickerOptions" :clearable="false" :key="endkey">
                        </el-date-picker>
                    </td>
                    <td>检验组</td>
                    <td>
                        <el-select v-model="labgroupid" placeholder="选择检验组" style="width: 100%;">
                                <el-option label="全部" value=""></el-option>
                                <el-option v-for="(item,index) in gList" :key="index" :label="item.labgroupname" :value="item.labgroupid"></el-option>
                            </el-select>
                    </td>
                    <td>病历号</td>
                    <td>
                        <el-input size="small" style="width:100%;" v-model="patno" placeholder="病历号" ref="refQuicklyQ" @focus="Focus($event)"></el-input>
                    </td>
                    <td>姓名</td>
                    <td>
                        <el-input size="small" style="width:100%;" v-model="patname" placeholder="姓名" ref="refQuicklyQ" @focus="Focus($event)"></el-input>
                    </td>                    
                    <td>复查状态</td>
                    <td>
                        <el-select v-model="checkflag" placeholder="选择检验组" style="width: 100%;">
                                <el-option label="全部" value=""></el-option>
                                <el-option label="已复查" value="1"></el-option>
                                <el-option label="未复查" value="2"></el-option>
                            </el-select>
                    </td>    
                </tr>
                <tr>
                    <td>报告单元</td>
                    <td>
                        <rm-ddl-rptunit prgno="LIS440" v-model="rptunit" width="100%" clearable @change="rptunitChange"></rm-ddl-rptunit>
                    </td>   
                    <td>病人来源</td>
                    <td>
                        <el-select v-model="pattypecode" @dblclick.native="popMultipleChk(pattypecode,'pattypecode',pattypeOption,'病人类型选择')" filterable clearable style="width:100%">
                            <el-option v-for="(item,index) in pattypeOption" :value="item.data" :label="item.display" :key="index"></el-option>
                        </el-select>
                    </td>  
                    <td>科室</td>
                    <td>
                        <rm-ddl-common datatype="dept" dataname="科室" v-model="deptno" width="100%" @change="deptChange"></rm-ddl-common>
                    </td>    
                    <td>病区</td>
                    <td>
                        <rm-ddl-common :appendtobody="true" datatype="ward" dataname="病区" v-model="wardno" width="100%" @change="wardChange"></rm-ddl-common>
                    </td>
                    <td>报告项目</td>
                    <td>
                        <rm-ddl-rptitem prgno="LIS440" :germmode="false" v-model="rptitemcode" width="100%" :appendtobody="true" @change="rptitemChange"></rm-ddl-rptitem>
                    </td>
                    <td colspan="2">
                        <el-checkbox  v-model="onlyrech">仅显示复查的项目</el-checkbox>
                    </td>
                </tr>
                <tr>
                    <td colspan="13">
                        <el-button icon="el-icon-search" v-has="'PINQUERY'" type="primary" @click="BtnQuery">查询(F8)</el-button>
                        <el-button icon="el-icon-sort" @click="btnSort">排序</el-button>
                        <el-button icon="el-icon-delete" @click="btn_clearselEvent">清除</el-button>
                        <el-button @click.native="BtnPrintDesign(1)" icon="el-icon-printer">打印</el-button>
                        <el-button @click.native="BtnPrintDesign(2)" icon="el-icon-edit-outline">打印样式</el-button>
                        <el-button @click.native="exportExcel" icon="el-icon-zoom-in">导出</el-button>
                        <el-button icon="el-icon-setting" @click="setExportColumn">导出列设置</el-button>
                    </td>
                </tr>
            </table>
        </div>
        <div class="pagecenter">
            <!-- <div :style="middle_center"> -->
            
                    <rm-layout-right splitcolor="#ffffff" :splitwidth="2" :fixsize="475" :minfixsize="200" ref="layoutright">
                        <vxe-table :data.sync="report_data" :loading="report_Loading" :select-config="{reserve: true}" :sort-config="{trigger: 'cell'}" border :height="reportheight" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="reportTable" resizable show-overflow size="mini" :row-class-name="reportRowName" show-header-overflow :optimization="{animat: false}" @current-change="reportchange_Event" @cell-click="cellClickEvent" :cell-class-name="reportCellName" @cell-dblclick="cellDblClickEvent" header-align="center">
                            <!-- @cell-click="cellClickEvent"  -->
                            
                            <!-- 添加打印选择-->
                            <vxe-table-column field="cp_selection" title="选择" width="40px" align="center">
                                <template v-slot:header="{ column }">
                                    <el-checkbox v-model="selectall" @change="ChkAll($event)"></el-checkbox>
                                </template>
                                <template v-slot="{ row, rowIndex }">
                                    <el-checkbox v-model="row.cp_selection" true-label="1" false-label="0" @change="handleCheckedPrintChange(row, rowIndex)"></el-checkbox>
                                </template>
                            </vxe-table-column>
                            <vxe-table-column field="alter_flag" title="警告" width="40" show-overflow align="center">
                                <template v-slot="{ row, rowIndex, columnIndex }">
                                    <el-checkbox v-model="row.isalter_flag" true-label="1" false-label="0" disabled></el-checkbox>
                                </template>
                            </vxe-table-column>
                            <vxe-table-column field="emer_flag" title="加急" width="40" show-overflow align="center">
                                <template v-slot="{ row, rowIndex, columnIndex }">
                                    <el-checkbox v-model="row.isemer_flag" true-label="1" false-label="0" disabled></el-checkbox>
                                </template>
                            </vxe-table-column>
                            <vxe-table-column field="rechkflag" title="审核" width="40" show-overflow align="center">
                                <template v-slot="{ row, rowIndex, columnIndex }">
                                    <div :key="row.userno+rowIndex+columnIndex" v-if="row.rechkflag == '9'">
                                        <font color="#000000">审</font>
                                    </div>
                                    <div :key="row.userno+rowIndex+columnIndex" v-else>
                                    </div>
                                </template>
                            </vxe-table-column>
                            <vxe-table-column field="rptunitname" title="报告单元" width="130" show-overflow></vxe-table-column>
                            <vxe-table-column align="center" field="sampledate" title="标本日期" width="70" :formatter="['toDateString', 'yyyy-MM-dd']" show-overflow></vxe-table-column>
                            <vxe-table-column field="sampleno" align="center" title="标本号" width="60" show-overflow :sort-width="20"></vxe-table-column>
                            <vxe-table-column field="pat_name" align="center" title="病人姓名" width="60" show-overflow></vxe-table-column>
                            <vxe-table-column field="pat_no" title="病人号" width="100" show-overflow></vxe-table-column>
                            <vxe-table-column field="pat_sexname" align="center" title="性别" width="35" show-overflow></vxe-table-column>
                            <vxe-table-column field="rechk_dt" align="center" title="审核时间" width="120" show-overflow></vxe-table-column>
                            <vxe-table-column field="rechk_user" align="center"  title="审核医生" width="60" show-overflow></vxe-table-column>
                            <vxe-table-column field="redo_flag"  title="复查标志" width="90" show-overflow></vxe-table-column>
                            <vxe-table-column field="print_count"  title="打印次数" width="40" show-overflow></vxe-table-column>
                            <vxe-table-column field="tat_recieve_report" align="center"  title="接收-报告（分钟）" width="40" show-overflow></vxe-table-column>
                            <vxe-table-column field="tat_sampled_recieve"  title="采样-接收（分钟）" width="40" show-overflow></vxe-table-column>
                            <vxe-table-column field="req_reason" title="送检目的" width="400" show-overflow></vxe-table-column>
                            <vxe-table-column field="pat_agestr" align="center"  title="年龄" width="40" show-overflow></vxe-table-column>
                            <vxe-table-column field="specimen"  title="标本类型" width="100" show-overflow></vxe-table-column>
                            <vxe-table-column field="req_bedno"  title="床号" width="50" show-overflow></vxe-table-column>
                            <vxe-table-column field="pat_typecodename"  title="病人类别" width="80" show-overflow></vxe-table-column>
                            <vxe-table-column field="barcode" align="center"  title="条码号" width="100" show-overflow></vxe-table-column>
                            <vxe-table-column field="req_dept"  title="申请科室" width="150" show-overflow></vxe-table-column>
                            <vxe-table-column field="req_ward" align="center"  title="病人病区" width="120" show-overflow></vxe-table-column>
                            <vxe-table-column field="charge_typeno" align="center" title="收费类别" width="90" show-overflow></vxe-table-column>
                            <vxe-table-column field="pat_diag" title="临床诊断" width="250" show-overflow></vxe-table-column>
                            <vxe-table-column field="req_dt" align="center" title="申请时间" width="140" show-overflow></vxe-table-column>
                            <vxe-table-column field="req_doc" align="center" title="申请医生" width="70" show-overflow></vxe-table-column>
                           <vxe-table-column field="sampled_dt" align="center"  title="采样时间" width="140" show-overflow></vxe-table-column>
                            <vxe-table-column field="recieve_dt" align="center"  title="接收时间" width="140" show-overflow></vxe-table-column>
                            <vxe-table-column field="input_dt" align="center"  title="录入时间" width="140" show-overflow></vxe-table-column>
                            <vxe-table-column field="test_info"  title="上机信息" width="120" show-overflow></vxe-table-column>
                            <vxe-table-column field="test_dt" align="center"  title="上机时间" width="140" show-overflow></vxe-table-column>
                            <vxe-table-column field="report_dt" align="center"  title="报告时间" width="140" show-overflow></vxe-table-column>
                            <vxe-table-column field="report_username" align="center"  title="检验医生" width="70" show-overflow></vxe-table-column>
                            <vxe-table-column field="report_comm"  title="报告单备注" width="150" show-overflow></vxe-table-column>
                            <vxe-table-column field="lab_advice"  title="实验室意见" width="100" show-overflow></vxe-table-column>
                            <vxe-table-column field="item_num" align="center"  title="项目数" width="50" show-overflow></vxe-table-column>
                            <vxe-table-column field="instr_advice"  title="仪器辅助诊断" width="150" show-overflow></vxe-table-column>
                            <vxe-table-column field="rechk2_dt" align="center"  title="二审时间" width="140" show-overflow></vxe-table-column>
                            <vxe-table-column field="rechk2_user" align="center"  title="二审医生" width="70" show-overflow></vxe-table-column>
                            <vxe-table-column field="lastprint_dt" align="center"  title="最后打印时间" width="140" show-overflow></vxe-table-column>
                            <vxe-table-column field="" align="center"  title="计价" width="140" show-overflow></vxe-table-column>
                            <vxe-table-column field="prereport_dt" align="center"  title="预计报告时间" width="140" show-overflow></vxe-table-column>
                            <vxe-table-column field="reportid"  title="报告ID" width="160" show-overflow></vxe-table-column>
                            <vxe-table-column field="hospcode"  title="送检医院" width="180" show-overflow></vxe-table-column>
                            <vxe-table-column field="sample_detail" align="center"  title="标本状态备注" width="140" show-overflow></vxe-table-column>
                            <vxe-table-column field="reportid"  title="申请单ID" width="100" show-overflow></vxe-table-column>
                            <vxe-table-column field="pat_cardno" align="center"  title="就诊卡号" width="110" show-overflow></vxe-table-column>
                            <vxe-table-column field="inp_id" title="就诊号" width="100" show-overflow></vxe-table-column>
                            <vxe-table-column field="inp_date" align="center" title="入院日期" width="140" show-overflow></vxe-table-column>
                            <vxe-table-column field="pat_phone" title="联系电话" width="100" show-overflow></vxe-table-column>
                            <vxe-table-column field="pat_id" align="center"  title="病人ID" width="130" show-overflow></vxe-table-column>
                            <vxe-table-column field="last_dt"  title="最后修改时间" width="120" show-overflow></vxe-table-column>
                            <vxe-table-column field="release_dt"  title="发布时间" width="140" show-overflow></vxe-table-column>
                            <vxe-table-column field="release_user" align="center"  title="发布人" width="70" show-overflow></vxe-table-column>
                            <vxe-table-column field="is_changed" align="center"  title="是否修改" width="70" show-overflow></vxe-table-column>
                            <vxe-table-column field="changed_afterreport" align="center" sortable title="打印、审核后修改" width="130" show-overflow></vxe-table-column>
                            <vxe-table-column field="unprint_flag" align="center" sortable title="禁止打印标志" width="100" show-overflow></vxe-table-column>
                            <vxe-table-column field="unprint_reason" sortable title="禁止打印原因" width="120" show-overflow></vxe-table-column>
                        </vxe-table>
                        <template v-slot:fix>
                            <div class="right-inser">
                                    <vxe-table :data.sync="result_data" :loading="result_Loading" header-align="center" :select-config="{reserve: true}" :sort-config="{trigger: 'cell'}" border height="100%" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow ref="ymresulttable" resizable show-overflow size="mini" stripe show-header-overflow :optimization="{animat: false}">
                                        <vxe-table-column type="index" title="NO." width="60"></vxe-table-column>
                                        <vxe-table-column field="rpt_itemname" title="检验项目" width="220" show-overflow> <template v-slot="{ row }">
                                            <div v-if="row.alertflag == '1'" style="background:red;padding:0px 10px">
                                                {{ row.rpt_itemname }}
                                            </div>
                                            <div v-else style="padding:0px 10px">
                                                {{ row.rpt_itemname }}
                                            </div>
                                        </template></vxe-table-column>
                                    <vxe-table-column field="result_str" title="检测结果" width="80" show-overflow> <template v-slot="{ row }">
                                            <div :style="{
                            background: row.cp_resultbackgroundcolor,
                            color: row.cp_resultcolor
                          }" style="padding:0px 10px">
                                                {{ row.result_str }}
                                            </div>
                                        </template></vxe-table-column>
                                        <vxe-table-column field="redo_flag" align="center" title="复查标志" width="60" show-overflow></vxe-table-column>
                                    <vxe-table-column field="redo_result" title="复查前结果" width="120" show-overflow></vxe-table-column>
                                    <vxe-table-column field="result_ref"  title="参考值" width="100" show-overflow></vxe-table-column>
                                    <vxe-table-column field="result_unit"  title="单位" width="70" show-overflow></vxe-table-column>
                                    <vxe-table-column field="redo_reason" title="复查原因" width="120" show-overflow></vxe-table-column>
                                    <!-- <vxe-table-column field="result1" :title="result1text" width="70px" v-if="result1 == 1"></vxe-table-column>
                                    <vxe-table-column field="result2" :title="result2text" width="70px" v-if="result2 == 1"></vxe-table-column>
                                    <vxe-table-column field="result3" :title="result3text" width="70px" v-if="result3 == 1"></vxe-table-column> -->
                                    <vxe-table-column field="result_txt"  title="大文本结果" width="130" show-overflow></vxe-table-column>
                                    <vxe-table-column field="instrid"  title="检验仪器" width="100" show-overflow></vxe-table-column>
                                    <vxe-table-column field="interno"  title="通道号" width="100" show-overflow></vxe-table-column>
                                    <vxe-table-column field="alertflag" align="center"  title="危急标志" width="60" show-overflow></vxe-table-column>
                                    <vxe-table-column field="result_flag" align="center"  title="结果标志" width="60" show-overflow></vxe-table-column>
                                    <vxe-table-column field="orig_result_num"  title="原始数值结果" width="120" show-overflow></vxe-table-column>
                                    <vxe-table-column field="orig_result_str"  title="原始文本结果" width="120" show-overflow></vxe-table-column>

                                    <vxe-table-column field="itemcode_en"  title="英文缩写" width="60" show-overflow></vxe-table-column>

                                    <vxe-table-column field="modify_flag" align="center"  title="修改标志" width="60" show-overflow></vxe-table-column>
                                    <vxe-table-column field="first_dt" align="center"  title="第一次填入时间" width="120" show-overflow></vxe-table-column>
                                    <vxe-table-column field="last_dt" align="center"  title="最后修改时间" width="120" show-overflow></vxe-table-column>
                                    <vxe-table-column field="last_user" align="center"  title="最后修改人" width="80" show-overflow></vxe-table-column>
                                    <vxe-table-column field="rptunitid"  title="报告单元" width="150" show-overflow></vxe-table-column>
                                    <vxe-table-column field="germflag" align="center"  title="细菌标志" width="60" show-overflow></vxe-table-column>

                                    <vxe-table-column field="orig_result_str"  title="分组序号" width="60" show-overflow></vxe-table-column>
                                    <vxe-table-column field="orig_result_str"  title="打印序号" width="60" show-overflow></vxe-table-column>

                                    <vxe-table-column field="orig_result_flag" align="center"  title="原始结果标志" width="160" show-overflow></vxe-table-column>
                                    </vxe-table>
                            </div>
                        </template>
                    </rm-layout-right>
           
               <el-dialog title="导出列选择" :visible.sync="chooseColumndialogVisible" width="380px" v-el-drag-dialog :close-on-click-modal="false">
                    <rm-excolsetting :excolPro="excolPro" :allTableCol="allTableCol" @change="saveExportColumn"></rm-excolsetting>
                </el-dialog>
                <rm-excolsetting :excolPro="excolPro" :allTableCol="allTableCol" @change="saveExportColumn" ref="excolset" v-show="false"></rm-excolsetting>
            <!-- </div> -->
        </div>
    </div>
</template>


<script>
import RmExcolsetting from "@/components/rmcompents/rm_excolsetting.vue";
import XE from "xe-utils"; //引入工具类
XE.mixin({
    // 自定义全局的格式化处理函数
    formatSelect(cellValue, list) {
        let item = list.find((item) => item.value == cellValue);
        return item ? item.label : "";
    },
});
export default {
    name: "LIS440",
    components: { RmExcolsetting },
    data() {
        const _that = this;
        return {
            pagetopstyle: {
                height: "150px",
            },
            report_Loading: false,
            report_data: [],
            fieldname: "",
            dlgTitle: "",
            sample_startdt: this.$pub.InitDateTime2(0).datefrom,
            sample_enddt: this.$pub.InitDateTime2(0).dateto,
            labgroupid: "",
            patno: "",
            patname: "",
            rptunit: "",
            pattypecode: "",
            deptno: "",
            wardno: "",
            rptitemcode: "",
            checkflag: "",
            onlyrech:false,
            macaddress: "",
            result_data: [],
            result_Loading: false,
            resusltmed_date: [],
            master_data: [],
            checkRefData: [],
            allTableCol: [],
            tableColumn:[],
            sortArr: [],
            excolPro: "lis440",
            master_Loading: false,
            dialogCheckRefVisible: false, //校验参考值
            dialogErrCheckVisible: false, //失败弹窗
            chooseColumndialogVisible: false,
            cellreportid: "",
            reportheight: "auto",
            resultheight: "auto",
            ymresultheight: "auto",
            startkey: 0,
            endkey: 0,
            rpt_amount: 0,
            check_amount: 0,
            check_num: 0,
            mstr_amount: 0,
            result_amount: 0,
            ymresult_amont: 0,
            ymresultitem_amount: 0,
            printReportid: "",
            reportid: "",
            rechkflag: "",
            option1: [],
            option2: [],
            pattypeOption: [],
            newArray: [],
            checkObj: {},
            msglist: [],
            gList:[],
            result1text: "",
            result2text: "",
            result3text: "",
            result1: "",
            result2: "",
            result3: "",
            pickerOptions: {
                //添加跳转今天
                shortcuts: [
                    {
                        text: "今天",
                        onClick(picker) {
                            picker.$emit("pick", new Date());
                            _that.sample_startdt = new Date();
                            _that.sample_enddt = new Date();
                        },
                    },
                ],
            },
            //导出修改
            bExportSettingsVisible: false, //导出设置弹窗
            exportFileTitle: "@sampledate_@sampleno_@rptunitid_@pat_no_@pat_name",
            exampleTitle: "@sampledate_@sampleno_@rptunitid_@pat_no_@pat_name",
            logList: [],
            exportIndex: 0,
            dialogVisible: false,
            printmsg: "",
            selectall: false, //全选  用于打印/导出的全选
            howdays: 1, //查询几天内的报告
            rptunitname: "",
            deptname: "",
            wardname: "",
            rptitemname: "",
        };
    },
    created() {
        this.initOption();
        this.initDate();
        this.btn_clearselEvent();
        
    },
    mounted() {
        //定义快捷键F8
        var _this = this;
        document.onkeydown = function (e) {
            let key = window.event.keyCode;
            switch (key) {
                case 119: //查询F8
                    _this.BtnQuery();
                    break;
            }
        };
		this.$refs.excolset.colSettingToDB();
    },
    updated() {},
    methods: {
        popMultipleChk(e, fieldname, option, title) {
            let temp = XE.clone(option, true);
            this.option1 = [];
            this.option2 = [];
            if (e != "") {
                let k = e.split(",");
                k.forEach((item) => {
                    let ndata = temp.find((m) => m.data == item);
                    if (ndata != undefined && ndata != null) {
                        this.option2.push(ndata);
                    }
                });
                temp.forEach((item) => {
                    if (k.indexOf(item.data + "") < 0) {
                        this.option1.push(item);
                    }
                });
            } else {
                this.option1 = temp;
            }
            this.fieldname = fieldname;
            this.dlgTitle = title;
            this.dialogMultipleVisible = true;
        },
        async initOption() {
            if (typeof jsObj != "undefined") {
                var computeInfo = jsObj.GetComputeInfo();
                var arr = computeInfo.split("\r");
                if (arr.length == 3) {
                    this.macaddress = arr[0];
                }
            } else {
                this.macaddress = "Default";
            }
            try {
                const res = await this.$tool.request({
                    url: "LIS/LIS4/LIS440",
                    method: "post",
                    data: {
                        action: "initOption",
                    },
                });
                
                // this.labgroupid = res.defid;//默认检验组
                this.gList = res.glist;
                this.pattypeOption = res.pattypeOption;
            } catch (e) {
                this.$message.warning(e);
            }
        },
        //取设置默认时间\
        async initDate() {
            try {
                const res = await this.$tool.request({
                    url: "LIS/LIS4/LIS440",
                    method: "post",
                    data: {
                        action: "initDate",
                    },
                });
                if (res) {
                    this.howdays = XE.toInteger(res);
                    if (this.howdays >= 1) {
                        this.sample_startdt = this.$pub.InitDateTime2(this.howdays - 1).datefrom;
                    }
                }
            } catch (e) {
                this.$message.warning(e);
            }
        },

        BtnQuery() {
            this.report_Loading = true;
            this.selectall = false; // 用于重置全选
            this.printReportid = "";
            this.rechkflag = "";
            this.exportna = "";
            this.$tool
                .request({
                    url: "LIS/LIS4/LIS440",
                    method: "post",
                    data: {
                        action: "query",
                        stime: this.sample_startdt,
                        etime: this.sample_enddt,
                        labgroupid: this.labgroupid,
                        patno: this.patno,
                        patname: this.patname,
                        rptunit: this.rptunit,
                        pattypecode: this.pattypecode,
                        deptno: this.deptno,
                        wardno: this.wardno,
                        rptitemcode: this.rptitemcode,
                        checkflag: this.checkflag,
                        sortArr: this.sortArr,
                    },
                })
                .then((res) => {
                    this.report_data = res.data;
                    this.result_data = [];
                    this.report_Loading = false;
                    if (res.total > 5000) {
                        this.$message({
                            type: "info",
                            message: "超过5000行只显示前5000行数据！",
                        });
                    }
                    this.$refs.refQuicklyQ.focus();
                    if (this.report_data.length > 0) {
                        this.$refs.reportTable.setCurrentRow(this.report_data[0]);
                        this.fuc_get_labresult(this.report_data[0]);
                        this.cellreportid = this.report_data[0].reportid;
                        this.printReportid = this.report_data[0].reportid;
                        this.rechkflag = this.report_data[0].rechkflag;
                        this.exportna = this.report_data[0].reportid + "-" + this.report_data[0].pat_name;
                    }
                    this.rpt_amount = res.total;
                    this.initColumns();
                })
                .catch((e) => {
                    this.$message.error(e);
                });
        },
        reportchange_Event({ row, rowIndex, column, columnIndex }, event) {
            this.printReportid = row.reportid;
            this.rechkflag = row.rechkflag;
            this.exportna = row.reportid + "-" + row.pat_name;            
            this.fuc_get_labresult(row);            
        },
        cellClickEvent({row,column}){
            if(column.property!="cp_selection"){
            if(row.cp_selection=='1')
            row.cp_selection='0';
            else
            row.cp_selection='1';
            
            if (row.cp_selection != "0") {
                if (row.notserviceprint == "1") {
                    row.cp_selection = "0";
                }
                if (row.rechkflag != 9) {
                    row.cp_selection = "0";
                }
                if (row.prereport == "1") {
                    row.cp_selection = "0";
                }
                if (["1", "2", "8"].includes(row.unprint_flag)) {
                    if (row.unprint_flag == "1") {
                        row.cp_selection = "0";
                    } else if (["8"].includes(row.unprint_flag)) {
                        row.cp_selection = "0";
                    }
                } else {
                    this.$nextTick(() => {
                        row.cp_selection == "0" ? "1" : "0";
                    });
                }
            }
            }
        },
        fuc_get_labresult(row) {
            this.result_Loading = true;
            this.$tool
                .request({
                    url: "LIS/LIS4/LIS440",
                    method: "post",
                    data: {
                        action: "get_labresult",
                        reportid: row.reportid,
                        rptunitid: row.rptunitid,
                        macaddress: this.macaddress,
                        onlyrech:this.onlyrech?'1':'0',
                    },
                })
                .then((res) => {
                    if (res.rtn.length > 1) {
                        //药敏
                        this.result_data = res.rtn[0];
                        this.resusltmed_date = res.rtn[1];
                        this.result_amount = this.result_data.length;
                        this.ymresultitem_amount = this.resusltmed_date.length;
                    } else {
                        this.result_data = res.rtn[0];
                        this.result_amount = this.result_data.length;
                    }
                    this.result_Loading = false;
                })
                .catch((e) => {
                    this.$message.error(e);
                });
        },
        rptunitChange(code, name) {
            this.rptunitid = code;
            this.rptunitname = name;
        },
        deptChange(code, name) {
            this.deptno = code;
            this.deptname = name;
        },
        wardChange(code, name) {
            this.wardno = code;
            this.wardname= name;
        },
        rptitemChange(code, name) {
            this.rptitemcode = code;
            this.rptitemname = name;
        },
        exportExcel() {
            var rightlocalStorage = JSON.parse(window.localStorage.getItem(this.excolPro + "exportCol"));
            let tableColumn = this.$refs.reportTable.getColumns();
            let exportColumn = [];
            if (rightlocalStorage && rightlocalStorage.length > 0) {
                rightlocalStorage.forEach(item => {
                    exportColumn.push({
                        title: item.extitle ? item.extitle : item.title,
                        field: item.property
                    });
                });
            } else {
                tableColumn.forEach((item) => {
                    exportColumn.push({ title: item.title, field: item.property });
                });
            }
            let filtertxt = this.getExportFilter();
            this.$pub.exportTableExcel(this.report_data, exportColumn, "LIS440 复查报告清单.xlsx", filtertxt);
        },
        // 获取当前导出文件的所有查询条件
        getExportFilter() {
            let filtertxt = "标本日期:" + XE.toDateString(this.sample_startdt, "yyyy-MM-dd") + "至" + XE.toDateString(this.sample_enddt, "yyyy-MM-dd ") + "; ";
            if(this.labgroupid) filtertxt += "检验组:" + this.getOptionName(this.gList.filter((item) =>  this.labgroupid == item.labgroupid)) + "; ";
            if(this.patno) filtertxt += "病历号:" + this.patno + "; ";
            if(this.patname) filtertxt += "姓名:" + this.patname + "; ";
            filtertxt += "复查状态:" + (this.checkflag == "1" ? "已复查" : this.checkflag == "2" ? "未复查" : "全部") + "; ";
            if(this.rptunitid) filtertxt += "报告单元:" + this.rptunitname + "; ";
            if(this.pattypecode) filtertxt += "病人来源:" + this.getOptionName(this.pattypeOption.filter((item) =>  ("," + this.pattypecode + ",").indexOf("," + item.data + ",") > -1)) + "; ";
            if(this.deptno) filtertxt += "科室:" + this.deptname + "; ";
            if(this.wardno) filtertxt += "病区:" + this.wardname + "; ";
            if(this.rptitemcode) filtertxt += "报告项目:" + this.rptitemname + "; ";
            if(this.onlyrech) filtertxt += "仅显示复查的项目; ";
            return filtertxt;
        },
        getOptionName(option) {
            if (option && option.length > 0) {
                let optionname = "";
                option.forEach((item) => {
                    if(item.hasOwnProperty("labgroupname")) {
                        optionname += item.labgroupname + ",";
                    } else {
                        optionname += item.display + ",";
                    }
                });
                return optionname.substring(0, optionname.length - 1);
            } else {
                return "";
            }
        },
        setExportColumn() {
            let allColumnList = [];
            let allTableCol = this.$refs.reportTable.getTableColumn().tableColumn;
            allTableCol.forEach(element => {
                if (element.property) {
                    allColumnList.push({
                        title: element.title,
                        property: element.property
                    });
                }
            });
            this.allTableCol = allColumnList;
            this.chooseColumndialogVisible = true;
        },
        saveExportColumn() {
            this.chooseColumndialogVisible = false;
        },
        btn_clearselEvent() {
            this.report_Loading = false;
            this.report_data = [];
            this.result_data = [];
            this.resusltmed_date = [];
            this.quicklyQ = "";
            this.sample_startdt= this.$pub.InitDateTime2(0).datefrom,
            this.sample_enddt= this.$pub.InitDateTime2(0).dateto,
            this.labgroupid= "",
            this.patno= "",
            this.patname= "",
            this.rptunit= "",
            this.pattypecode= "",
            this.deptno= "",
            this.wardno= "",
            this.rptitemcode="",
            this.checkflag= "",
            this.onlyrech=false,
            this.printReportid = "";
            this.rechkflag = "";
            this.exportna = "";
            this.sortArr = [];
        },
        
        
        //"rm-cancel"; //作废
        //"rm-disable"; //禁用
        //"rm-readonly"; //只读
        //"rm-alert"; //警告
        reportRowName({ row, rowIndex }) {
            if (this.cellreportid == row.reportid) {
                // return "rm-red";
            }
            if (row.rechk_dt != "" && row.rechk_dt != " " && row.rechk_dt != null) {
                if (XE.toNumber(row.print_count) > 0) {
                    return "rm-gray"; //审核过打印的
                } else {
                    return "colrow"; //没打印的
                }
            }
        },
        btnSort() {
            this.$rmsort(
                { tableColumn: this.tableColumn, sortArr: this.sortArr },
                {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning",
                }
            )
                .then((res) => {
                    this.sortArr = res.data;
                    this.BtnQuery();
                })
                .catch(() => {});
        },
        initColumns() {
            if (this.tableColumn.length == 0) {
                let columns = this.$refs.reportTable.getColumns();
                columns.forEach((item) => {
                    this.tableColumn.push({ title: item.title, field: item.property });
                });
            }
        },
        reportCellName({ row, rowIndex, column, columnIndex }) {
            if (column.property == "alter_flag") {
                if (row.alter_flag == "1" || row.alter_flag == "2") {
                    row.isalter_flag=row.alter_flag=="1" || row.alter_flag == "2";
                    return "colred";
                }
            } else if (column.property == "redo_flag") {
                if (row.redo_flag == "2" || row.redo_flag == "3") {
                    return "colgreen";
                }
            } else if (column.property == "pat_name" || column.property == "pat_no") {
                // 添加链接查询颜色
                return "col-blue";
            } else if (column.property == "unprint_reason") {
                return "col-red";
            }

            // if (column.property == "emer_flag") {
            //     if (row.emer_flag != "0") {
            //         return "rm_cell_green";
            //     }
            // }
        },
        BtnPrintDesign(val){
            let checkdata=this.report_data.filter(x=>x.cp_selection=='1');
            if (checkdata.length > 0)
            {
            this.$tool
                .request({
                    url: "LIS/LIS4/LIS440",
                    method: "post",
                    data: {
                        action: "getprintsql",
                        stime: this.sample_startdt,
                        etime: this.sample_enddt,
                        labgroupid: this.labgroupid,
                        patno: this.patno,
                        patname: this.patname,
                        rptunit: this.rptunit,
                        pattypecode: this.pattypecode,
                        deptno: this.deptno,
                        wardno: this.wardno,
                        rptitemcode: this.rptitemcode,
                        checkflag: this.checkflag,
                        onlyrech:this.onlyrech?'1':'0',
                        checkdata:checkdata,
                        sortArr: this.sortArr,
                    },
                })
                .then((res) => {
                    // 打印样式设计
                let str = res.sqlstr;
                console.log('sql:',str);
                let sql = btoa(encodeURIComponent(str));
                if(val=="2")
                jsObj.SetCustomPrintConfig("5062", sql, this.userno, "复查报告清单");
                else
                jsObj.PrintCustomReport("5062", sql, this.userno, "复查报告清单","");
                
                })
                .catch((e) => {
                    this.$message.error(e);
                });
            }
            else{
                this.$message.warning("请先选择一份报告进行打印!");
            }
        },
        
        //双击链接查询
        cellDblClickEvent({ row, column }) {
            if (column.property == "pat_no") {
                this.patno = row.pat_no;
                this.BtnQuery();
            } else if (column.property == "pat_name") {
                this.patname = row.pat_name;
                this.BtnQuery();
            }
        },
        //全选/取消
        ChkAll(e) {
            if (this.report_data != null && this.report_data.length > 0) {
                this.report_data.forEach((item) => {
                    item.cp_selection = this.selectall == true ? "1" : "0";

                    if (item.cp_selection != "0") {
                        if (item.notserviceprint == "1") {
                            item.cp_selection = "0";
                        }
                        if (item.rechkflag != 9) {
                            item.cp_selection = "0";
                        }
                        if (item.prereport == "1") {
                            item.cp_selection = "0";
                        }
                        if (["1", "2", "8"].includes(item.unprint_flag)) {
                            if (item.unprint_flag == "1") {
                                item.cp_selection = "0";
                            } else if (["8"].includes(item.unprint_flag)) {
                                item.cp_selection = "0";
                            }
                        } else {
                            this.$nextTick(() => {
                                item.cp_selection == "0" ? "1" : "0";
                            });
                        }
                     }
                });
            }
        },
        // 勾选点击提示
        handleCheckedPrintChange(row, rowIndex) {
            //控制单选状态
            if (row.cp_selection != "0") {
                if (row.notserviceprint == "1") {
                    this.$alert("当前报告不可在服务台打印！", "提示", {
                        confirmButtonText: "确定",
                        callback: (action) => {
                            this.$nextTick(() => {
                                row.cp_selection = "0";
                            });
                        },
                    });
                }
                if (row.rechkflag != 9) {
                    //9已审核
                    this.$alert("当前报告未审核，不可打印！", "提示", {
                        confirmButtonText: "确定",
                        callback: (action) => {
                            this.$nextTick(() => {
                                row.cp_selection = "0";
                            });
                        },
                    });
                }
                if (row.prereport == "1") {
                    this.$alert("当前报告为初步报告，只可查询，不可打印！", "提示", {
                        confirmButtonText: "确定",
                        callback: (action) => {
                            this.$nextTick(() => {
                                row.cp_selection = "0";
                            });
                        },
                    });
                }
                if (["1", "2", "8"].includes(row.unprint_flag)) {
                    if (row.unprint_flag == "1") {
                        this.$confirm("当前报告禁止自助打印，" + row.unprint_reason + "，打印未通过，你是否确定要打印？", "提示", {
                            confirmButtonText: "确定",
                            cancelButtonText: "取消",
                            type: "warning",
                        })
                            .then(() => {
                                this.$nextTick(() => {
                                    row.cp_selection = "1";
                                });
                            })
                            .catch((e) => {
                                this.$nextTick(() => {
                                    row.cp_selection = "0";
                                });
                            });
                    } else if (["8"].includes(row.unprint_flag)) {
                        let msg = "当前报告禁止在服务台打印！";
                        if (row.unprint_flag == "8") {
                            msg = "当前报告需要单独授权才能打印，请到指定地点或用户处打印！";
                        }
                        this.$alert(msg, "提示", {
                            confirmButtonText: "确定",
                            callback: (action) => {
                                this.$nextTick(() => {
                                    row.cp_selection = "0";
                                });
                            },
                        });
                    }
                } else {
                    this.$nextTick(() => {
                        row.cp_selection == "0" ? "1" : "0";
                    });
                }
            }
        },
        Focus(event) {
            event.currentTarget.select();
        },
    },
};
</script>

<style scoped>
::v-deep .el-checkbox__inner::after {
    border: 2px solid #000000 !important;
    box-sizing: content-box;
    content: "";
    border-left: 0 !important;
    border-top: 0 !important;
    height: 7px;
    left: 4px;
    position: absolute;
    top: 1px;
    transform: rotate(45deg) scaleY(0);
    width: 3px;
    transition: transform 0.15s ease-in 0.05s;
    transform-origin: center;
}
::v-deep .el-checkbox__input.is-disabled + span.el-checkbox__label {
    color: #000000;
    cursor: not-allowed;
}
::v-deep .el-checkbox__input.is-disabled .el-checkbox__inner,
.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner + .el-input.is-disabled .el-input__inner {
    background-color: #ffffff !important;
}
::v-deep .el-input--suffix .el-input__inner {
    padding-right: 5px;
}
.middle-tab-bottom {
    position: absolute;
    top: 0px;
    width: 100%;
    bottom: 0px;
    overflow: auto;
}
.pagetop {
   left: 0;
    right: 0;
    height: 100px;
    display: -webkit-box;
    -webkit-box-pack: center;
    -webkit-box-align: center;
    border: solid 1px #ccc;
    position: absolute;
    z-index: 99;
}
.pagecenter {
    position: absolute;
    top: 105px;
    width: 100%;
    left: 0;
    bottom: 0px;
    overflow: auto;
}
.pagebottom {
    position: absolute;
    width: 100%;
    left: 0;
    margin-top: 4px;
    height: 36px;
    bottom: 0px;
    -webkit-box-pack: center;
    -webkit-box-align: center;
    border: solid 1px #ccc;
}

.right-inser {
    position: absolute;
    top: 0;
    bottom: 0px;
    overflow: auto;
    width: 100%;
    right: 0px;
}

table tr td:nth-child(odd) {
    text-align: right;
    white-space: nowrap;
}
table tr td:nth-child(even) {
    text-align: left;
}
table tr td:nth-child(1) {
    width: 80px;
}
table {
    font-size: 12px;
    border-collapse: separate;
    border-spacing: 5px;
}
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}
.avatar-uploader .el-upload:hover {
    border-color: #409eff;
}
.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
}
.avatar {
    width: 178px;
    height: 178px;
    display: block;
}

.avatar-uploader-icon1 {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 50px;
    line-height: 50px;
    text-align: center;
}
.avatar1 {
    width: 178px;
    height: 50px;
    display: block;
}
.middle-tab-top {
    position: absolute;
    top: 0px;
    width: 100%;
    height: 200px;
}
.middle-bottom {
    position: absolute;
    top: 37px;
    width: 100%;
    bottom: 0px;
    overflow: auto;
}
.middle-tab-bottom {
    position: absolute;
    top: 203px;
    width: 100%;
    bottom: 0px;
    overflow: auto;
}
.poppagetop {
    width: 100%;
    height: 24px;
    -webkit-box-pack: left;
    -webkit-box-align: center;
    position: absolute;
    /* border: 1px solid #ccc; */
    z-index: 999;
}
.poppagecenter {
    position: absolute;
    overflow: auto;
    top: 27px;
    width: 100%;
    height: 450px;
    left: 0;
}
::v-deep .el-select-dropdown__wrap {
    max-width: 400px;
}
::v-deep .vxe-table .vxe-body--row.row--hover td {
    background-color: #d7f1fd;
    vertical-align: top !important;
}
::v-deep .vxe-table.size--mini .vxe-body--column,
.vxe-table.size--mini .vxe-footer--column,
.vxe-table.size--mini .vxe-header--column {
    padding: 1px 0;
    vertical-align: top !important;
}
::v-deep .vxe-table .vxe-sort-wrapper {
    padding: 0 0px;
}
::v-deep .colred {
    background-color: red !important;
}
::v-deep .colgreen {
    background-color: #00ff00 !important;
}
::v-deep .colrow {
    background-color: #c0ffc0;
}
::v-deep .el-input.is-disabled .el-input__inner {
    color: #606266;
    cursor: default;
}
::v-deep .vxe-table .vxe-body--column.col-blue {
    color: blue;
}
::v-deep .vxe-table .vxe-body--column.col-red {
    color: red;
}
</style>